package com.aya;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.spring.ReferenceBean;
import com.alibaba.dubbo.rpc.RpcContext;
import com.aya.service.DemoModel;
import com.aya.service.DemoService;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.Future;

/**
 * @description:
 * @date: Created in 18:14 2018/10/8
 */
public class ConsumerInvokeSimple {
    static Logger logger = LoggerFactory.getLogger(ConsumerInvokeSimple.class);
    public static void main(String[] args) throws InterruptedException, IOException, KeeperException {
//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("consumer.xml");
//        ReferenceBean<DemoService> bean = applicationContext.getBean("&demoNewService", ReferenceBean.class);
        ReferenceConfig<DemoService> bean = new ReferenceConfig<>();
        bean.setApplication(new ApplicationConfig("app-consumer"));
        bean.setRegistry(new RegistryConfig("zookeeper://localhost:2181"));
        bean.setInterface(DemoService.class);
        bean.setVersion("1.0.0");
        bean.setRetries(0);
        bean.setTimeout(60*1000);
        bean.setCheck(false);
        bean.setAsync(true);
        DemoService demoService = bean.get();
        try {
            DemoModel de = new DemoModel();
            de.setContent("content");
            de.setName("zhangsan");
            String s = demoService.sayHello("ss");
            Future<String> future = RpcContext.getContext().getFuture();
            String o = future.get();
            logger.info("响应的内容:{}", o);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
